﻿using System;

namespace Pharma
{
    public class Medicine
    {
        public int medicineCode;
        public string medicineName;
        public int manufacturerName;
        public double unitPrice;
        public int quantityOnHand = 0;
        public DateTime manufacturedDate;
        public DateTime expiryDate;
        public int batchNo;
        public string[] manufac = new string[3] { "Manufacted 1", "Manufacted 2", "Manufacted 3" };

        public bool Accept()
        {
            LB:
            try
            {
                Console.Write("Enter the Medicine Code:");
                medicineCode = Convert.ToInt32(Console.ReadLine());
                if (medicineCode <= 0)
                {
                    Console.WriteLine("Medicine Code <= 0");
                    goto LB;
                }
                foreach (var item in Test.md.list)
                {
                    if (item.medicineCode == medicineCode)
                    {
                        Console.WriteLine("Medicine Code identical");
                        goto LB;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message); 
                goto LB;
            }

            Console.Write("Enter the Medicine Name:");
            medicineName = Console.ReadLine();
            Console.Write("List Manufacturer Name");
            for (int i = 0; i < manufac.GetLength(0); i++)
            {
                Console.Write("\n\t" + i + " : " + manufac[i]);
            }
            Console.WriteLine();
            LB0:
            try
            {
                Console.Write("Enter the Manufacturer Name:");
                manufacturerName = Convert.ToInt32(Console.ReadLine());
                if (manufacturerName < 0 || manufacturerName > 2)
                {
                    Console.WriteLine("Manufacturer Name number can not < 0 or > 2");
                    goto LB0;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB0;
            }
            LB1:
            try
            {
                Console.Write("Enter the Unit Price:");
                unitPrice = Convert.ToDouble(Console.ReadLine());
                if (unitPrice <= 0)
                {
                    Console.WriteLine("Unit Price can not < 0");
                    goto LB1;
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB1;
            }
            LB2:
            try
            {
                Console.Write("Enter the Manufactured date :");
                manufacturedDate = Convert.ToDateTime(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB2;
            }
            LB3:
            try
            {
                Console.Write("Enter the Expiry date :");
                expiryDate = Convert.ToDateTime(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB3;
            }
            LB4:
            try
            {
                Console.Write("Enter the Batch Number:");
                batchNo = Convert.ToInt32(Console.ReadLine());
                if (batchNo <= 0)
                {
                    Console.WriteLine("Batch Number can not < 0");
                    goto LB4;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB4;
            }
            LB5:
            try
            {
                Console.Write("Enter the Quantity on Hand:");
                quantityOnHand = Convert.ToInt32(Console.ReadLine());
                if (quantityOnHand < 0)
                {
                    Console.WriteLine("Quantity on Hand number can not < 0");
                    goto LB5;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                goto LB5;
            }
            return true;
        }

        public void Print()
        {
            Console.WriteLine("Medicine Code: "+medicineCode);
            Console.WriteLine("Medicine Name: " + medicineName);
            Console.WriteLine("Manufacturer Name: " + manufacturerName);
            Console.WriteLine("Unit Price: " + unitPrice);
            Console.WriteLine("Manufactured date: " + manufacturedDate.ToShortDateString());
            Console.WriteLine("Expiry date: " + expiryDate.ToShortDateString());
            Console.WriteLine("Batch Number: " + batchNo);
            Console.WriteLine("Quantity on Hand: " + quantityOnHand);
        }
       
    }
}
